/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.adv;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.adv.HkCityInfo;
import com.thinkgem.jeesite.modules.hk.sys.service.adv.HkCityInfoService;

/**
 * 城市信息管理Controller
 * @author 罗天文
 * @version 2018-06-05
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/adv/hkCityInfo")
public class HkCityInfoController extends BaseController {

	@Autowired
	private HkCityInfoService hkCityInfoService;
	
	@ModelAttribute
	public HkCityInfo get(@RequestParam(required=false) String id) {
		HkCityInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkCityInfoService.get(id);
		}
		if (entity == null){
			entity = new HkCityInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:adv:hkCityInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkCityInfo hkCityInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkCityInfo> page = hkCityInfoService.findPage(new Page<HkCityInfo>(request, response), hkCityInfo); 
		model.addAttribute("page", page);
		return "hk/sys/adv/hkCityInfoList";
	}

	@RequiresPermissions("sys:adv:hkCityInfo:view")
	@RequestMapping(value = "form")
	public String form(HkCityInfo hkCityInfo, Model model) {
		model.addAttribute("hkCityInfo", hkCityInfo);
		return "hk/sys/adv/hkCityInfoForm";
	}

	@RequiresPermissions("sys:adv:hkCityInfo:edit")
	@RequestMapping(value = "save")
	public String save(HkCityInfo hkCityInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkCityInfo)){
			return form(hkCityInfo, model);
		}
		hkCityInfoService.save(hkCityInfo);
		addMessage(redirectAttributes, "保存城市信息管理成功");
		return "redirect:"+Global.getAdminPath()+"/sys/adv/hkCityInfo/?repage";
	}
	
	@RequiresPermissions("sys:adv:hkCityInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(HkCityInfo hkCityInfo, RedirectAttributes redirectAttributes) {
		hkCityInfoService.delete(hkCityInfo);
		addMessage(redirectAttributes, "删除城市信息管理成功");
		return "redirect:"+Global.getAdminPath()+"/sys/adv/hkCityInfo/?repage";
	}

}